package offer;

import java.util.Stack;

public class Question {
    public static void main(String[] args) {
        /*MinStack minStack = new MinStack();
        minStack.push(512);
        minStack.push(-1204);
        minStack.push(-1204);
        minStack.push(512);
        minStack.pop();
        System.out.println(minStack.min);
        minStack.pop();
        System.out.println(minStack.min);
        minStack.pop();
        System.out.println(minStack.min);
        minStack.pop();*/
        String s = "We are happy.";

    }
    //把空格替换成%20
    public String replaceSpace(String s) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < s.length(); i++) {
            char temp = s.charAt(i);
            if (temp == ' '){
                sb.append("%20");
            }else {
                sb.append(temp);
            }
        }
        return sb.toString();
    }

    //根据数字 左旋转字符串
    public String reverseLeftWords(String s, int n) {
        StringBuilder sb = new StringBuilder();
        int a=0,b=n;
        while(b != s.length()){
            sb.append(s.charAt(b++));
        }
        while (a != n){
            sb.append(s.charAt(a++));
        }
        return sb.toString();
    }
    
}
class CQueue {
    Stack<Integer> s1 ;
    Stack<Integer> s2 ;
    public CQueue() {
        s1 = new Stack<Integer>();
        s2 = new Stack<Integer>();
    }

    public void appendTail(int value) {
        s1.push(value);
    }

    public int deleteHead() {
        if (s1.empty())return -1;
        while(!s1.empty()){
            s2.push(s1.pop());
        }
        int result = s2.pop();
        while(!s2.empty()){
            s1.push(s2.pop());
        }
        return result;
    }
}
//想法
//维护两个栈结构  一个正常存东西
class MinStack {
    Stack<Integer> normal;
    Stack<Integer> min;
    /** initialize your data structure here. */
    public MinStack() {
        normal = new Stack<>();
        min = new Stack<>();
    }

    public void push(int x) {
        int minTemp = 0;
        if (normal.empty() || x <= min.peek()){
            normal.add(x);
            minTemp = x;
            min.add(minTemp);
        }else {
            normal.add(x);
        }
    }

    public void pop() {
      if (normal.pop().equals(min.peek())){
          min.pop();
      }
    }

    public int top() {
        return normal.peek();
    }

    public int min() {
        return min.peek();
    }
}